<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>产品单品</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="__STATIC__/layout/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__STATIC__/layout/css/font-awesome.css?v=4.4.0" rel="stylesheet">
   
    <link href="__STATIC__/layout/css/animate.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/zTreeStyle/demo.css" type="text/css">
    <link rel="stylesheet" href="__STATIC__/zTreeStyle/zTreeStyle.css" type="text/css">
     <link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
    <style>
       #alertmod_table_list_2 {
            top: 900px !important;
        }
        .alerts{display:none;position:fixed;top:0;left:0;width: 100%;height: 100%;background: rgba(0,0,0,0.5);}
       .alerts .alerts_content{background:#fff;position: fixed;top: 50%;left: 50%; width: 700px;min-height: 500px;margin: -220px 0 0 -350px;padding:5px;border:4px solid #ccc/* margin 负值为宽高的一半 */}
        .wait{ display:none;background:#f4f4f5;position: fixed;top: 50%;left: 50%; width: 700px;min-height: 250px;margin: -220px 0 0 -350px;padding:5px;border:4px solid #ccc/* margin 负值为宽高的一半 */}
       .alerts .alerts_content h3{font-weight: normal;text-align:left;line-height: 24px;font-size: 16px;padding-left: 1%;width: 99%;margin-bottom:30px;background: #d0e0e0}
       .alerts .alerts_content .alerts_form{
        width:100%;
       }
         .alert_addNewZone_tree{display:none;position:fixed;top:0;left:0;width: 100%;height: 100%;background: rgba(0,0,0,0.5);}
       .alert_addNewZone_tree .alert_addNewZone_content_tree{background:#fff;position: fixed;top: 50%;left: 50%; width: 500px;height: 300px;margin: -150px 0 0 -250px;border:4px solid #ccc;box-sizing: border-box;overflow: hidden;/* margin 负值为宽高的一半 */}
       .alert_addNewZone_tree .alert_addNewZone_content_tree h3{font-weight: normal;text-align:left;line-height: 24px;font-size: 16px;padding-left: 1%;width: 100%;background: #d0e0e0}
       .alert_addNewZone .alert_addNewZone_content .alert_addNewZone_form{
        width:100%;
       }
       .alert_addNewZone_tree .alert_addNewZone_content_tree .alert_addNewZone_form_tree{
        height: 280px;
        width: 100%;
        overflow-x: hidden;
        overflow-y: auto;
       }
       .alerts .alerts_content .alerts_form form{width: 100%;}
       .alerts .alerts_content .alerts_form form div{margin-bottom:30px;width: 100%;text-align: center;}
       .alerts .alerts_content .alerts_form form div label{display:inline-block;width: 130px;text-align: right;}
       .alerts .alerts_content .alerts_form form div:nth-of-type(1) input{margin-right: 28px;}
        .mtp{margin-top:3px;}
        .no-padding{padding: 0;}
        #gopage{color:blue;cursor: pointer;}
        #firstpage{cursor: pointer;}


           .alert_addNewZone_tree{display:none;position:fixed;top:0;left:0;width: 100%;height: 100%;background: rgb(255,255,255,0.7);z-index: 200}
       .alert_addNewZone_tree .alert_addNewZone_content_tree{background:#fff;position: fixed;top: 50%;left: 50%; width: 500px;height: 350px;margin: -150px 0 0 -250px;border:4px solid #ccc;box-sizing:border-box;overflow: hidden;/* margin 负值为宽高的一半 */}
       .wait,.waits{background:#f4f4f5;position: fixed;top: 50%;left: 50%; width: 500px;height: 300px;margin: -150px 0 0 -250px;padding:5px;border:4px solid #ccc/* margin 负值为宽高的一半 */}
       .alert_addNewZone_tree .alert_addNewZone_content_tree h3{font-weight: normal;text-align:left;line-height: 24px;font-size: 16px;padding-left: 1%;width: 100%;background: #d0e0e0}
    </style>
</head>

<body class="white-bg" style="color:#333;">
    	  <div class="page-heade">
       <h2 class="title_color text-center">	
       	{if condition="$pid eq 0"}
			添加单品
			{else/}
			编辑单品
			{/if}</h2>
    </div>
       
        <input type="hidden" value="{$pid}" id="pid"/>
        <div class="col-md-12" style="padding:3px;">
			
				<table class="table table-bordered bud_hei" style="width: 100%;">
					<tr class='font-bold'>
						<td colspan="6" class="info">基础信息</td>
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">产品编号<span style="color: red">*</span>:</td>
						<td style="width:23%;"><input type="text" id="pro_no" class="form-control" {if condition='$parr.pro_no neq ""'} readonly value="{$parr.pro_no}" {/if} /></td>
						<td colspan="4" style="color: red">
							(温馨提示，如不填写系统将自动分配)
						</td>
						
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">产品名称<span style="color: red">*</span>:</td>
						<td style="width:23%;"><input type="text" id="pro_name" value="{$parr.pro_name}" class="form-control" /></td>
						<td style="width: 10%;">产品零售单位:<span style="color: red">*</span></td>
						<td style="width:23%;">
							<input type="text" id="unit" class="form-control" value="{$parr.unit}" />
						</td>
						<td style="width: 10%;">产品重量(克/毫升):</td>
						<td style="width:23%;">
							<input type="text" id="weight" class="form-control"  value="{$parr.weight}"/>
						</td>
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">产品条形码(SKU):</td>
						<td style="width:23%;"><input type="text" id="pro_sku" value="{$parr.pro_sku}" class="form-control" /></td>
						<td style="width: 10%;">发运及库存基本单位:<span style="color: red">*</span></td>
						<td style="width:23%;">
							<select id="base_unit_id" class="form-control">
								{if condition='$parr.base_unit_id eq 0'}
								<option value="0" selected>请选择</option>
								{else/}
								<option value="0">请选择</option>
								{/if}
								{if condition='$parr.base_unit_id eq 1'}
								<option value="1" selected>箱</option>
								{else/}
								<option value="1">箱</option>
								{/if}
								{if condition="$parr.unit neq ''"}
									{if condition='$parr.base_unit_id eq 2'}
									<option value="2" selected>{$parr.unit}</option>
									{else/}
									<option value="2">{$parr.unit}</option>
									{/if}
								{/if}
							</select>
						</td>
						<td style="width: 10%;">单品规格:</td>
						<td style="width:23%;">
							<input type="text" id="format" class="form-control" value="{$parr.format}"/>
						</td>
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">所属SKU:<span style="color: red">*</span></td>
						<td style="width:23%;">
							<span id="sku_kg">
								{if condition="$parr.sku_name neq ''"}
								<span style='background:#d0e0e0;border:1px solid #ccc;border-radius:5px;padding:2px 3px;'>{$parr.sku_name}&nbsp;&nbsp;<span onclick='clear_sku();' style='cursor:pointer;font-size: 16px'>x</span>
								{/if}
							</span>
							<input type="hidden"  id="sku_id" value="{$parr.sku_id}"/>
							<a href='javascript:;' id="choose_sku">选择</a>
						</td>
						<td style="width: 10%;">箱规(()/每箱):<span style="color: red">*</span></td>
						<td style="width:23%;">
							<input type="text" id="box_num" class="form-control int_num" value="{$parr.box_num}"/>
						</td>
						<td style="width: 10%;"></td>
						<td style="width:23%;">
							
						</td>
					</tr>
					<tr class='font-bold'>
						<td colspan="6" class="info">物流信息</td>
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">箱毛重（公斤）:</td>
						<td style="width:23%;"><input type="text" id="box_weight" value="{$parr.box_weight}" class="form-control float_num" /></td>
						<td style="width: 10%;">箱体积（立方米）:</td>
						<td style="width:23%;">
							<input type="text" id="box_volume" value="{$parr.box_volume}" class="form-control float_num" />
						</td>
						<td style="width: 10%;">纸箱尺寸(毫米):</td>
						<td style="width:23%;">
							<input type="text" id="box_size" value="{$parr.box_size}" class="form-control float_num" />
						</td>
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">产品箱外码:</td>
						<td style="width:23%;"><input type="text" id="box_no" value="{$parr.box_no}" class="form-control" /></td>
						<td style="width: 10%;"></td>
						<td style="width:23%;">
							
						</td>
						<td style="width: 10%;"></td>
						<td style="width:23%;">
							
						</td>
					</tr>
					<tr class='font-bold'>
						<td colspan="6" class="info">价格信息-出厂价（一级经销商供货价）</td>
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">标准出厂价(<span class="danwei"></span>)<span style="color: red">*</span>:</td>
						<td style="width:23%;"><input type="text" id="factory" value="{$parr.factory}" class="form-control float_num" /></td>
						<td style="width: 10%;">标准成本价(<span class="danwei"></span>):</td>
						<td style="width:23%;"><input type="text" id="cost" value="{$parr.cost}" class="form-control float_num" /></td>
							
						</td>
						<td style="width: 10%;">出厂毛利率(<span class="danwei"></span>):</td>
						<td style="width:23%;">
							<span id="fac_maoli"></span>%
						</td>
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">标准出厂价(箱)<span style="color: red">*</span>:</td>
						<td style="width:23%;"><input type="text" id="box_factory" value="{$parr.box_factory}" class="form-control float_num" /></td>
						<td style="width: 10%;">标准成本价(箱):</td>
						<td style="width:23%;"><input type="text" id="box_cost" value="{$parr.box_cost}" class="form-control float_num" /></td>
							
						</td>
						<td style="width: 10%;">出厂毛利率(箱):</td>
						<td style="width:23%;">
							<span id="box_fac_maoli"></span>%
						</td>
					</tr>
					<tr class='font-bold'>
						<td colspan="6" class="info">价格信息-二级经销商供货价</td>
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">建议经销商二级供货价(<span class="danwei"></span>):</td>
						<td style="width:23%;"><input type="text" id="availability" value="{$parr.availability}" class="form-control float_num" /></td>
						<td style="width: 10%;">建议经销商二级供货价(箱):</td>
						<td style="width:23%;"><input type="text" id="box_availability" value="{$parr.box_availability}" class="form-control float_num" /></td>
							
						</td>
						<td style="width: 10%;"></td>
						<td style="width:23%;">
							
						</td>
					</tr>
					<tr class='font-bold'>
						<td colspan="6" class="info">价格信息-零售商供价</td>
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">零售商标准供货价(<span class="danwei"></span>):</td>
						<td style="width:23%;"><input type="text" id="retail_standard" value="{$parr.retail_standard}" class="form-control float_num" /></td>
						<td style="width: 10%;">零售商标准供货价(箱):</td>
						<td style="width:23%;"><input type="text" id="box_retail_standard" value="{$parr.box_retail_standard}" class="form-control float_num" /></td>
							
						</td>
						<td style="width: 10%;">一级经销商倒扣毛利率(标准):</td>
						<td style="width:23%;">
							<span id="retail_maoli"></span>%
						</td>
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">零售商最低供货价(<span class="danwei"></span>):</td>
						<td style="width:23%;"><input type="text" id="retail_low" value="{$parr.retail_low}" class="form-control float_num" /></td>
						<td style="width: 10%;">零售商最低供货价(箱):</td>
						<td style="width:23%;"><input type="text" id="box_retail_low" value="{$parr.box_retail_low}" class="form-control float_num" /></td>
							
						</td>
						<td style="width: 10%;"></td>
						<td style="width:23%;">
							
						</td>
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">零售商最高供货价(<span class="danwei"></span>):</td>
						<td style="width:23%;"><input type="text" id="retail_high" value="{$parr.retail_high}" class="form-control float_num" /></td>
						<td style="width: 10%;">零售商最高供货价(箱):</td>
						<td style="width:23%;"><input type="text" id="box_retail_high" value="{$parr.box_retail_high}" class="form-control float_num" /></td>
							
						</td>
						<td style="width: 10%;"></td>
						<td style="width:23%;">
							
						</td>
					</tr>
					<tr class='font-bold'>
						<td colspan="6" class="info">价格信息-常规零售价</td>
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">公司标准零售价(<span class="danwei"></span>):</td>
						<td style="width:23%;"><input type="text" id="sell_standard" value="{$parr.sell_standard}" class="form-control float_num" /></td>
						<td style="width: 10%;">公司标准零售价(箱):</td>
						<td style="width:23%;"><input type="text" id="box_sell_standard" value="{$parr.box_sell_standard}" class="form-control float_num" /></td>
							
						</td>
						<td style="width: 10%;">零售商倒扣毛利率(标准):</td>
						<td style="width:23%;">
							<span id="retail_maoli"></span>%
						</td>
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">公司最低零售价(<span class="danwei"></span>):</td>
						<td style="width:23%;"><input type="text" id="sell_low" value="{$parr.sell_low}" class="form-control float_num" /></td>
						<td style="width: 10%;">公司最低零售价(箱):</td>
						<td style="width:23%;"><input type="text" id="box_sell_low" value="{$parr.box_sell_low}" class="form-control float_num" /></td>
							
						</td>
						<td style="width: 10%;"></td>
						<td style="width:23%;">
							
						</td>
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">公司最高零售价(<span class="danwei"></span>):</td>
						<td style="width:23%;"><input type="text" id="sell_high" value="{$parr.sell_high}" class="form-control float_num" /></td>
						<td style="width: 10%;">公司最高零售价(箱):</td>
						<td style="width:23%;"><input type="text" id="box_sell_high" value="{$parr.box_sell_high}" class="form-control float_num" /></td>
							
						</td>
						<td style="width: 10%;"></td>
						<td style="width:23%;">
							
						</td>
					</tr>
					<tr class='font-bold'>
						<td colspan="6" class="info">价格信息-促销零售价</td>
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">公司最低促销价(<span class="danwei"></span>):</td>
						<td style="width:23%;"><input type="text" id="promotion_low" value="{$parr.promotion_low}" class="form-control float_num" /></td>
						<td style="width: 10%;">公司最低促销价(箱):</td>
						<td style="width:23%;"><input type="text" id="box_promotion_low" value="{$parr.box_promotion_low}" class="form-control float_num" /></td>
							
						</td>
						<td style="width: 10%;"></td>
						<td style="width:23%;">
							
						</td>
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">公司最高促销价(<span class="danwei"></span>):</td>
						<td style="width:23%;"><input type="text" id="promotion_high" value="{$parr.promotion_high}" class="form-control float_num" /></td>
						<td style="width: 10%;">公司最高促销价(箱):</td>
						<td style="width:23%;"><input type="text" id="box_promotion_high" value="{$parr.box_promotion_high}" class="form-control float_num" /></td>
							
						</td>
						<td style="width: 10%;"></td>
						<td style="width:23%;">
							
						</td>
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">促销惊爆价(<span class="danwei"></span>):</td>
						<td style="width:23%;"><input type="text" id="promotion_shocking" value="{$parr.promotion_shocking}" class="form-control float_num" /></td>
						<td style="width: 10%;">促销惊爆价(箱):</td>
						<td style="width:23%;"><input type="text" id="box_promotion_shocking" value="{$parr.box_promotion_shocking}" class="form-control float_num" /></td>
							
						</td>
						<td style="width: 10%;"></td>
						<td style="width:23%;">
							
						</td>
					</tr>
					<tr class='font-bold'>
						<td colspan="6" class="info">其他信息</td>
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">进场限制</td>
						<td colspan="5">
							{volist name="pro_entry" id="vo"}
								{if condition="$parr.entry eq $vo.id"}
								<label><input type="radio" value="{$vo.id}" checked name="pro_entry"/>{$vo.entry_name}</label>
								{else/}
								<label><input type="radio" value="{$vo.id}" name="pro_entry"/>{$vo.entry_name}</label>
								{/if}
							{/volist}
						</td>
						
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">销售渠道-二级渠道</td>
						<td colspan="5">
							<span id="channel_type_kg">
								{if condition='$parr.title neq ""'}
								<span style='background:#d0e0e0;border:1px solid #ccc;border-radius:5px;padding:2px 3px;'>{$parr.title}&nbsp;&nbsp;<span onclick='clear_er();' style='cursor:pointer;font-size: 16px'>x</span>
								{/if}
							</span>
							<input type="hidden" id="channel_type" value="{$parr.channel_type}"/>
							<a href='javascript:;' id="choose_er">选择</a>
						</td>
						
					</tr>
					<tr style="font-size:14px;">
						<td style="width: 10%;">备注</td>
						<td colspan="5">
							<input type="text" id="remark" class="form-control" value="{$parr.remark}" />
						</td>
						
					</tr>
					<tr class='text-center'>
						<td colspan="6">
							<button id="submits" class="btn btn-success">确定</button>
							<button id="back" class="btn btn-warning">返回列表</button>
						</td>
						
					</tr>
				</table>
			

				
			</div>
        
  

    </div>
     <!--树状弹框-->
		<div class="alert_addNewZone_tree">
	        <div class="alert_addNewZone_content_tree">
	            <h3><span id="txtree"></span><a style="float: right;margin-right: 10px;font-size: 30px" id="del_this1">&times;</a></h3>
	            <div  class="alert_addNewZone_form_tree" id="fenqu_fzr">
	              <ul id="tree_em" class="ztree"></ul>
	               <div class="quedingbtn" style="position: absolute;right: 0;bottom: 10px;"><button class="btn btn-success" id="qd">确定</button></div>
	            </div>
	            
	        </div>
	        <div class="wait">
   				<div class="ibox ">
                    <div class="ibox-title">
                        <h5>正在处理，请稍后.....</h5>
                    </div>
                    <div class="ibox-content">
                        <div class="spiner-example">
                            <div class="sk-spinner sk-spinner-chasing-dots">
                                <div class="sk-dot1"></div>
                                <div class="sk-dot2"></div>
                            </div>
                        </div>
                    </div>
                </div>

	        </div>
  		 </div>
        <!--树状弹框-->
	
    <!-- 全局js -->
    <script src="__STATIC__/layout/js/jquery.min.js?v=2.1.4"></script>
    <script src="__STATIC__/layout/js/bootstrap.min.js?v=3.3.6"></script>
     <!-- Peity -->
    <script src="__STATIC__/layout/js/plugins/peity/jquery.peity.min.js"></script>
    <!-- 自定义js -->
    <script src="__STATIC__/layout/js/content.js?v=1.0.0"></script>
     <script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>
     <!-- layerDate plugin javascript -->
    <script src="__STATIC__/layout/js/plugins/layer/laydate/laydate.js"></script>
    <!-- ztree -->
    <script type="text/javascript" src="__STATIC__/zTreeStyle/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="__STATIC__/zTreeStyle/jquery.ztree.excheck.js"></script>
    <!--统计代码，可删除-->
	<script type="text/javascript">
	//产品名正则
 	var regex=/^[a-zA-Z0-9\u4e00-\u9fa5]{1,30}$/;
 	//产品编号
	var regex_no=/^[a-zA-Z0-9_\-]{1,20}$/;
	//产品零售单位
	var regex_unit=/^[a-zA-Z0-9_\-()（）\u4e00-\u9fa5]{1,20}$/;
	$("#submits").click(function(){
		//数字单元格处理
		$(".int_num").each(function(){
			  if(isNaN(parseInt($(this).val()))){
                $(this).val("");
            }else{
                $(this).val(parseInt($(this).val()));
            }

		})
		$(".float_num").each(function(){
			  if(isNaN(parseFloat($(this).val()))){
                $(this).val("");
            }else{
                $(this).val(parseFloat($(this).val()));
            }

		})
		//表单验证
		var msg="";
		if($("#pro_name").val()==""){
			msg="产品名不能为空";
		}else if(!regex.test($("#pro_name").val().replace(/(^\s*)|(\s*$)/g, ""))){
			msg="产品名称为字母，数字，中文，()，_，- 组成且长度不超过30";
		}else if($("#unit").val()==""){
			msg="产品零售单位不能为空";
		}else if(!regex_unit.test($("#unit").val())){
			msg="产品零售单位为字母，数字，中文组成且长度不超过20";
		}else if($("#base_unit_id").val()==0){
			msg="发运及库存基本单位必须选择";
		}else if($("#sku_id")==""){
			msg="必须选择所属sku";
		}
		else if($("#box_num").val()==""){
			msg="箱规必须填写";
		}else if($("#factory").val()==""||$("#box_factory").val()==""){
			msg="出厂价必须填写";
		}
		if(msg==""){
			//基本验证通过
			if($("#pid").val()==0){
				//添加
				 $(".alert_addNewZone_tree").show();
            	$("#txtree").html("正在处理，请稍后");
            	$("#fenqu_fzr").hide();
                $(".wait").show();
                $.post("{:url('Products/addp')}",
                	{
                		pro_no:$("#pro_no").val(),
                		pro_name:$("#pro_name").val(),
                		unit:$("#unit").val(),
                		weight:$("#weight").val(),
                		pro_sku:$("#pro_sku").val(),
                		base_unit_id:$("#base_unit_id").val(),
                		format:$("#format").val(),
                		sku_id:$("#sku_id").val(),
                		box_num:$("#box_num").val(),
                		box_weight:$("#box_weight").val(),
                		box_volume:$("#box_volume").val(),
                		box_size:$("#box_size").val(),
                		box_no:$("#box_no").val(),
                		factory:$("#factory").val(),
                		cost:$("#cost").val(),
                		box_factory:$("#box_factory").val(),
                		box_cost:$("#box_cost").val(),
                		availability:$("#availability").val(),
                		box_availability:$("#box_availability").val(),
                		retail_standard:$("#retail_standard").val(),
                		retail_low:$("#retail_low").val(),
                		retail_high:$("#retail_high").val(),
                		sell_standard:$("#sell_standard").val(),
                		sell_low:$("#sell_low").val(),
                		sell_high:$("#sell_high").val(),
                		promotion_low:$("#promotion_low").val(),
                		promotion_high:$("#promotion_high").val(),
                		promotion_shocking:$("#promotion_shocking").val(),
                		box_retail_standard:$("#box_retail_standard").val(),
                		box_retail_low:$("#box_retail_low").val(),
                		box_retail_high:$("#box_retail_high").val(),
                		box_sell_standard:$("#box_sell_standard").val(),
                		box_sell_low:$("#box_sell_low").val(),
                		box_sell_high:$("#box_sell_high").val(),
                		box_promotion_low:$("#box_promotion_low").val(),
                		box_promotion_high:$("#box_promotion_high").val(),
                		box_promotion_shocking:$("#box_promotion_shocking").val(),
                		pro_entry:$("input[name='pro_entry']:checked").val(),
                		channel_type:$("#channel_type").val(),
                		remark:$("#remark").val()
            		},function(re){
            			if(re!=""){
            				var data=JSON.parse(re);
            				if(data["state"]==1){
            					swal({
                                    title: "完成",
                                    text: data["msg"] ,
                                    type: "success"
                                    },function(){
                                        location.href='{:url("Products/products")}';
                                    });
            				}else{
            					swal({
								title: "错误",
								text:  data["msg"],
								type: "warning"
								});
            				}
            			}else{
            				swal({
							title: "错误",
							text:  "系统繁忙请稍后再试",
							type: "warning"
							});
            			}
            			 $(".alert_addNewZone_tree").hide();
            	
            		$("#fenqu_fzr").show();
                	$(".wait").hide();
                })
			}else{
				//修改
				
				 $(".alert_addNewZone_tree").show();
            	$("#txtree").html("正在处理，请稍后");
            	$("#fenqu_fzr").hide();
                $(".wait").show();
                $.post("{:url('Products/updatep')}",
                	{
                		pid:$("#pid").val(),
                		pro_name:$("#pro_name").val(),
                		unit:$("#unit").val(),
                		weight:$("#weight").val(),
                		pro_sku:$("#pro_sku").val(),
                		base_unit_id:$("#base_unit_id").val(),
                		format:$("#format").val(),
                		sku_id:$("#sku_id").val(),
                		box_num:$("#box_num").val(),
                		box_weight:$("#box_weight").val(),
                		box_volume:$("#box_volume").val(),
                		box_size:$("#box_size").val(),
                		box_no:$("#box_no").val(),
                		factory:$("#factory").val(),
                		cost:$("#cost").val(),
                		box_factory:$("#box_factory").val(),
                		box_cost:$("#box_cost").val(),
                		availability:$("#availability").val(),
                		box_availability:$("#box_availability").val(),
                		retail_standard:$("#retail_standard").val(),
                		retail_low:$("#retail_low").val(),
                		retail_high:$("#retail_high").val(),
                		sell_standard:$("#sell_standard").val(),
                		sell_low:$("#sell_low").val(),
                		sell_high:$("#sell_high").val(),
                		promotion_low:$("#promotion_low").val(),
                		promotion_high:$("#promotion_high").val(),
                		promotion_shocking:$("#promotion_shocking").val(),
                		box_retail_standard:$("#box_retail_standard").val(),
                		box_retail_low:$("#box_retail_low").val(),
                		box_retail_high:$("#box_retail_high").val(),
                		box_sell_standard:$("#box_sell_standard").val(),
                		box_sell_low:$("#box_sell_low").val(),
                		box_sell_high:$("#box_sell_high").val(),
                		box_promotion_low:$("#box_promotion_low").val(),
                		box_promotion_high:$("#box_promotion_high").val(),
                		box_promotion_shocking:$("#box_promotion_shocking").val(),
                		pro_entry:$("input[name='pro_entry']:checked").val(),
                		channel_type:$("#channel_type").val(),
                		remark:$("#remark").val()
            		},function(re){
            			if(re!=""){
            				var data=JSON.parse(re);
            				if(data["state"]==1){
            					swal({
                                    title: "完成",
                                    text: data["msg"] ,
                                    type: "success"
                                    });
            				}else{
            					swal({
								title: "错误",
								text:  data["msg"],
								type: "warning"
								});
            				}
            			}else{
            				swal({
							title: "错误",
							text:  "系统繁忙请稍后再试",
							type: "warning"
							});
            			}
            			 $(".alert_addNewZone_tree").hide();
            	
            		$("#fenqu_fzr").show();
                	$(".wait").hide();
                })
			}
		}else{
			swal({
					title: "错误",
					text:  msg,
					type: "warning"
				});
		}
	})
	$(function(){
		//unit_change();
		$("#unit").blur(unit_change);
		danmaoli();
		$("#factory").blur(danmaoli);
		$("#cost").blur(danmaoli);
		boxmaoli();
		$("#box_factory").blur(boxmaoli);
		$("#box_cost").blur(boxmaoli);
	})
	$("#back").click(function(){

		location.href='{:url("Products/products")}';
	})
	//整箱毛利计算
	function boxmaoli(){
		//(整箱出厂价-整箱成本价)/单件成本价
		//factory出厂  cost成本
		if(isNaN(parseFloat($("#box_factory").val()))){
			$("#box_factory").val("");
		}else{
			$("#box_factory").val(parseFloat($("#box_factory").val()));
		}
		if(isNaN(parseFloat($("#box_cost").val()))){
			$("#box_cost").val("");
		}else{
			$("#box_cost").val(parseFloat($("#box_cost").val()));
		}
		if($("#box_factory").val()!=""&&$("#box_cost").val()!=""){
			var res=($("#box_factory").val()-$("#box_cost").val())/$("#box_cost").val()*100;
			res=res.toFixed(2);
			$("#box_fac_maoli").html(res);
		}else{
			$("#box_fac_maoli").html("");
		}
		
	}
	//单件出厂毛利核算
	function danmaoli(){
		//(单件出厂价-单件成本价)/单件成本价
		//factory出厂  cost成本
		if(isNaN(parseFloat($("#factory").val()))){
			$("#factory").val("");
		}else{
			$("#factory").val(parseFloat($("#factory").val()));
		}
		if(isNaN(parseFloat($("#cost").val()))){
			$("#cost").val("");
		}else{
			$("#cost").val(parseFloat($("#cost").val()));
		}
		if($("#factory").val()!=""&&$("#cost").val()!=""){
			var res=($("#factory").val()-$("#cost").val())/$("#cost").val()*100;
			res=res.toFixed(2);
			$("#fac_maoli").html(res);
		}else{
			$("#fac_maoli").html("");
		}
		
	}
	//单位变化
	function unit_change(){
		var unit=$("#unit").val().replace(/(^\s*)|(\s*$)/g, "");
		if(unit==""){
			//无
			$(".danwei").html("");
			$("#base_unit_id").html('<option value="0">请选择</option><option value="1">箱</option>');
		}else{
			//有
			$(".danwei").html(unit);
			$("#base_unit_id").html('<option value="0">请选择</option><option value="1">箱</option><option value="2">'+unit+'</option>');
		}
	}
	function clear_sku(){
		$("#sku_id").val("");
		$("#sku_kg").html("");
	}
	function clear_er(){
		$("#channel_type").val("");
		$("#channel_type_kg").html("");
	}
		 //树
         function disabledNode(e) {
            var zTree = $.fn.zTree.getZTreeObj("tree_em"),
            disabled = e.data.disabled,
            nodes = zTree.getSelectedNodes();
            if (nodes.length == 0) {
                alert("请先选择一个节点");
            }

            for (var i=0, l=nodes.length; i<l; i++) {
                zTree.setChkDisabled(nodes[i], disabled);
            }
        }
        //选择sku
        var setting_sku={
            check: {
                enable: true,
                chkStyle: "radio",
                radioType: "all"
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback:{
                onCheck: skuOnCheck
            }
        };
           function skuOnCheck (event, treeId, treeNode){
        	if(treeNode.checked==true){
               	$("#sku_id").val(treeNode.id);
				$("#sku_kg").html("<span style='background:#d0e0e0;border:1px solid #ccc;border-radius:5px;padding:2px 3px;'>"+treeNode.name+"&nbsp;&nbsp;<span onclick='clear_sku();' style='cursor:pointer;font-size:16px'>x</span>");
                
            }else{
              clear_sku();
            }
        }
         //获取岗位列表
        $("#choose_sku").click(function(){
            $(".alert_addNewZone_tree").show();
            $("#txtree").html("SKU列表");
            $("#fenqu_fzr").hide();
                $(".wait").show();

           $.post("{:url('Productssku/getskulist')}",{skuid:$("#sku_id").val()},function(re){
           	
           		var data_sku=new Array();
           		if(re!=""){
					data_sku=JSON.parse(re);
           		}
                
                
                $("#fenqu_fzr").show();
                $(".wait").hide();
                $.fn.zTree.init($("#tree_em"), setting_sku, data_sku);
                $("#disabledTrue").bind("click", {disabled: true}, disabledNode);
                $("#disabledFalse").bind("click", {disabled: false}, disabledNode);
           })
       })
        /*   二级渠道树   */

        var setting_er={
            check: {
                enable: true,
                chkStyle: "radio",
                radioType: "all"
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback:{
                onCheck: erOnCheck
            }
        };
           function erOnCheck (event, treeId, treeNode){
        	if(treeNode.checked==true){
               	$("#channel_type").val(treeNode.id);
				$("#channel_type_kg").html("<span style='background:#d0e0e0;border:1px solid #ccc;border-radius:5px;padding:2px 3px;'>"+treeNode.name+"&nbsp;&nbsp;<span onclick='clear_er();' style='cursor:pointer;font-size:16px;'>x</span>");
                
            }else{
              clear_er();
            }
        }
       
        $("#choose_er").click(function(){
            $(".alert_addNewZone_tree").show();
            $("#txtree").html("二级渠道列表");
            $("#fenqu_fzr").hide();
                $(".wait").show();

           $.post("{:url('Products/getchannl')}",{cid:$("#channel_type").val()},function(re){
           	//alert(re);
           		var data_er=new Array();
           		if(re!=""){
					data_er=JSON.parse(re);
           		}
                
                
                $("#fenqu_fzr").show();
                $(".wait").hide();
                $.fn.zTree.init($("#tree_em"), setting_er, data_er);
                $("#disabledTrue").bind("click", {disabled: true}, disabledNode);
                $("#disabledFalse").bind("click", {disabled: false}, disabledNode);
           })
       })
          //关闭树
        
    	$("#del_this1").click(function(){
             
    		$(".alert_addNewZone_tree").hide();
    	})
        $("#qd").click(function(){
            
            $(".alert_addNewZone_tree").hide();
        })
	</script>

   	
</body>

</html>
